﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace B2B.Models
{
    public class ThongTinSanPham
    {
        private int maThongSo;

        public int MaThongSo
        {
            get { return maThongSo; }
            set { maThongSo = value; }
        }
        private string tenThongSo;

        public string TenThongSo
        {
            get { return tenThongSo; }
            set { tenThongSo = value; }
        }

        private int maSP;

        public int MaSP
        {
            get { return maSP; }
            set { maSP = value; }
        }

        private string chitiet;

        public string Chitiet
        {
            get { return chitiet; }
            set { chitiet = value; }
        }

        public ArrayList danhSachThongTinSanPham(int maDM)
        {
            SqlConnection conn = KetNoi.Connection();
            ArrayList list_TTSP = new ArrayList();
            SqlCommand cmd = new SqlCommand("SP_DANHSACHTHONGTINSP", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@MADM", maDM);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                ThongTinSanPham ttSP = new ThongTinSanPham();
                ttSP.MaThongSo = reader.GetInt32(0);
                ttSP.TenThongSo = reader.GetString(1);
                list_TTSP.Add(ttSP);
            }
            return list_TTSP;
        }

        public int ThemChiTietSanPham(ThongTinSanPham ttSP)
        {
            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("SP_THEMCHITIETSP", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@MATHONGSO", ttSP.MaThongSo);
            cmd.Parameters.AddWithValue("@MASP", ttSP.MaSP);
            cmd.Parameters.AddWithValue("@CHITIET", ttSP.Chitiet);
            conn.Open();
            int kq = cmd.ExecuteNonQuery();
            conn.Close();
            return kq;
        }
    }
}